package mt521.cam.ac.uk;

import java.io.File;

//Class to test various bits
public class TESTSRunCode {
    
    public static void main(String[] args) {
        //encodeFile();
        //encodeBytes();
        //decodeFile();
        //Encode.run(args);
        micTest();
    }
    
    public static void micTest() {
        byte[] bTone = FileOperators.mic(64);   //number of bytes to read is random at this stage
        System.out.println("Sound Captured.");
        double[] dTone = new double[bTone.length];
        for (int i=0; i<bTone.length; i++) {
            dTone[i] = (double)bTone[i];
        }
        double[] transformed = Decode.fft(dTone);
        long f = Decode.getFrequency(transformed);
        
        System.out.println("Frequency Heard: "+f);
        System.out.println("Byte Represented: "+(f-300)/30);
        Graph.graph(transformed);
    }
    
    public static void encodeFile() {
        File input = new File("dolphin.txt");
        byte[] bytes = FileOperators.convertToBytes(input);
        for(int i = 0; i<bytes.length; i++) {
            System.out.print(bytes[i]+" ");
        }
        Encode.encode(bytes);
    }
    
    public static void encodeBytes() {
        byte[] array = new byte[256];
        byte j = -128;
        for(int i = 0; i<128; i++) {
            array[i] = (byte)i;
        }
        for(int i = 0; i<128; i++, j++) {
            array[i+128] = j;
        }
        Encode.encode(array);
    }
    
    //run main with single string of the form "freq1,freq2,freq3a-freq3b-freq3c,freq4"
    /*public static void main(String[] args) {
        File input = new File("helloworld.txt");
        byte[] array = OpenFile.convertToBytes(input);
        String[] tones = {""};
        for (byte b : array) {
            tones[0] = tones[0] + Integer.toString(((int) b)*30)+",";
        }
        Encode.run(tones);
        System.out.println("Operation Complete");
        OpenFile.printBytes(input);
    }*/
    
}